#include <ros/ros.h>
#include <nodelet/nodelet.h>
#include <image_transport/subscriber.h>
#include <image_transport/image_transport.h>

#include <cv_bridge/CvBridge.h>
#include <opencv2/highgui/highgui.hpp>
//#include "window_thread.h"

#include <boost/thread.hpp>
#include <boost/format.hpp>

#ifdef HAVE_GTK
#include <gtk/gtk.h>

// Platform-specific workaround for #3026: image_view doesn't close when
// closing image window. On platforms using GTK+ we connect this to the
// window's "destroy" event so that image_view exits.
static void destroyNode(GtkWidget *widget, gpointer data)
{
  /// @todo On ros::shutdown(), the node hangs. Why?
  //ros::shutdown();
  exit(0); // brute force solution
}

static void destroyNodelet(GtkWidget *widget, gpointer data)
{
  // We can't actually unload the nodelet from here, but we can at least
  // unsubscribe from the image topic.
  reinterpret_cast<image_transport::Subscriber*>(data)->shutdown();
}
#endif


static const char WINDOW_NAME[] = "Unicebot Controler";

class MainWindow {
public:




	MainWindow();
	virtual ~MainWindow();
};

MainWindow::MainWindow() {
	cv::namedWindow(window_name_);

	#ifdef HAVE_GTK
	  // Register appropriate handler for when user closes the display window
	  GtkWidget *widget = GTK_WIDGET( cvGetWindowHandle(window_name_.c_str()) );
	  if (shutdown_on_close)
	    g_signal_connect(widget, "destroy", G_CALLBACK(destroyNode), NULL);
	  else
	    g_signal_connect(widget, "destroy", G_CALLBACK(destroyNodelet), &sub_);
	#endif

	  // Start the OpenCV window thread so we don't have to waitKey() somewhere
	  //startWindowThread();

}

MainWindow::~MainWindow() {
	// TODO Auto-generated destructor stub
}

/*

int main(int argc, char **argv)
{
  ros::init(argc, argv, "manager", ros::init_options::AnonymousName);
  ROS_WARN("##Je demarre");

  ros::NodeHandle n;
  ros::NodeHandle nh("~");

  // Command line argument parsing
  // First positional argument is the transport type
  std::string transport = "raw";
  for (int i = 0; i < argc; ++i)
  {
    if (argv[i][0] != '-')
    {
      transport = argv[i];
      break;
    }
  }


  // Instancier la fenetre principale
  //
  MainWindow* pWin = new MainWindow();

  // Instancier le viewer
  //
  Viewer* pViewer = new Viewer();


  // S'abboner à la publication "/image" avec le viewer en callback
  //
  image_transport::ImageTransport it(nh);
  //sub_ = it.subscribe(topic, 1, &imageCb, this, transport);
  pWin->sub_ = it.subscribe("/image", 3, &(pViewer->));

  ROS_WARN("####spin");
  ros::spin();
  return 0;
}
//*/
